//!
//! Copyright (c) 2024-2999 北京心月狐科技有限公司 All rights reserved.
//!
//! https://www.mxxshop.com
//!
//! Licensed 并不是自由软件，未经许可不能去掉 MxxShop 相关版权
//!
//! 版权所有，侵权必究！
//!
//! 
use crate::core::errors::error::Result;
use crate::modules::product::entity::cart_entity::Cart;
use crate::modules::product::entity::cart_model::CartSaveRequest;
use crate::pool;

pub async fn save_cart(item: CartSaveRequest) -> Result<u64>{
    let entity: Cart = item.into();
    // 启动一个事务
    let mut tx = pool!().acquire_begin().await?;
    let result = Cart::insert(&tx, &entity).await?;
    return if result.rows_affected > 0 {
        tx.commit().await?;
        tx.rollback().await?;
        Ok(result.rows_affected)
    }else{
        Ok(0)
    }
}
